﻿window.addEvent('domready', function () {
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    addEventToolTips();
});

function EndRequestHandler(sender, args) {
    addEventToolTips();
    $$('input.DatePicker').each(function (el) {
        new DatePicker(el);
    });
}

function addEventToolTips() {
    $$('input.DatePicker').each(function (el) {
        new DatePicker(el);
    });

    var tdToolTips = $$('td.toolTip');
    tdToolTips.each(function (item, index) {
        item.addEvents({
            'mouseenter': function (event) {
                showTooltips(item);
            },
            'mouseleave': function () {
                hidTooltips();
            }
        });
    });
}

function showTooltips(ctr) {
    ctr = $(ctr);
    var tooltip = $('tooltips');
    var dataTool = $('tool_' + ctr.get('id'));
    if (tooltip && dataTool) {
        var posX = ctr.getPosition().x;
        var posY = ctr.getPosition().y;
        tooltip.setPosition({ x: posX + 44, y: posY - 55 });
        tooltip.set('html', dataTool.get('html'));
        tooltip.setStyle('visibility', 'hidden');
        //tooltip.setStyle('display', 'block');
        tooltip.fade('in');
        //var t = 100;
        //(function () { tooltip.fade('out'); }).delay(t);
    }
}

function hidTooltips() {
    var tooltip = $('tooltips');
    if (tooltip) {
        tooltip.fade('out');
        //tooltip.setStyle('display', 'none');
    }
}